package com.jiuyuan.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jiuyuan.entity.Employee;
import com.jiuyuan.entity.vo.RespBean;
import com.jiuyuan.entity.vo.RespPageBean;
import com.jiuyuan.service.IEmployeeService;
import com.jiuyuan.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: hrms
 * @description:
 * @author: Feng
 * @create: 2023-02-19 13:34
 **/

@RestController
@RequestMapping("/salary/config/")
public class SalarySobCfgController {
    @Autowired
    ISalaryService salaryService;
    @Autowired
    IEmployeeService employeeService;

    @ApiOperation("获取所有帐套")
    @GetMapping("/")
    public RespBean list(){
        return RespBean.success(salaryService.list());
    }


    @ApiOperation("获取所有员工帐套")
    @GetMapping("/employeesWithSalaries")
    public RespPageBean employeesWithSalary(@RequestParam(defaultValue = "1") Integer currentPage,
                                                 @RequestParam(defaultValue = "10") Integer pageSize){
        return employeeService.employeeWithSaraly(currentPage,pageSize);
    }


    @ApiOperation("更新员工帐套")
    @PutMapping("/{eId}/{sId}")
    public RespBean update(@PathVariable Integer eId, @PathVariable Integer sId){
        boolean update = employeeService.update(new UpdateWrapper<Employee>().eq("id", eId).set("salaryId", sId));
        if(update) return RespBean.success("更新成功");
        return RespBean.error("更新失败");
    }
}
